package SqlService;

/**
 * Created by ghost461 on 17-5-8.
 */
import java.sql.*;

public class Sql {
	private Connection con;
	private String user="root";
	//private String password="lc971019";
	private String password="123";
	private String className = "com.mysql.jdbc.Driver";
	private String url="jdbc:mysql://localhost:3306/WifiObject?characterEncoding=utf8&useSSL=true";
	
	  public Sql()
	  {
		  try{
			  Class.forName(className);
			  System.out.println("驱动连接成功！");
		  }catch(ClassNotFoundException e){
			  System.out.println("驱动连接失败！");
			  e.printStackTrace();
				  
		  }
	  }
	  
	
	  public Connection getCon()
	  {
		  try{
			     con=DriverManager.getConnection(url,user,password);
			     System.out.println("数据库连接成功！");
		  }catch(SQLException e){
			  System.out.println("数据库连接失败！");
			  e.printStackTrace();
				  
		  }
		  return con;
	  }
	
	  public void closed()
	  {
		  try{
			    if(con!=null)  con.close();
		  }catch(SQLException e){
			  System.out.println("关闭连接失败！");
			  e.printStackTrace();
		  }
	  }
}